//
//  SaveDataMethord.m
//  ShoeSApp
//
//  Created by Jack's Mac on 2017/2/20.
//  Copyright © 2017年 Jack. All rights reserved.
//   数据保存

#import "SaveDataMethord.h"

@implementation SaveDataMethord

//1使用NSuserDefault保存用户密码
+(void)saveUserPwd:(NSString *)pwd{
    NSUserDefaults *myPwdData = [NSUserDefaults standardUserDefaults];
    [myPwdData setObject:pwd forKey:@"User_pwd"];
    [myPwdData synchronize];  //即时保存
   
}
//读取密码
+(NSString *)readUserPwd{
    NSUserDefaults *myPwdData = [NSUserDefaults standardUserDefaults];
    return [myPwdData objectForKey:@"User_pwd"];
}

//清除用户密码(置空操作)
+(void)clearnUserPwdData{
    NSUserDefaults *myPwdData = [NSUserDefaults standardUserDefaults];
    [myPwdData setObject:@"" forKey:@"User_pwd"];
    [myPwdData synchronize];  //即时保存
}



//读取存放在本地的用户登录后保存的信息
+ (NSMutableDictionary *)readLoginData {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    
    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"loginData.plist"];
    //读文件
    NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return dic;
}

//存储用户的的登录信息
+(void)SaveLoginDataToLocationWithDic:(NSMutableDictionary *)LoginDic{
    
    
   
    //1. 创建一个plist文件
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"loginData.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    
    //NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    //创建一个dic，写到plist文件里
    //    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];
    //    [dic writeToFile:filename atomically:YES];
    
    [LoginDic writeToFile:filename atomically:YES];
}

//清除登录时候的记录数据
+ (void)cleanloginData {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"loginData.plist"];
    NSMutableDictionary *dic = [[NSMutableDictionary alloc] initWithCapacity:0];
    [dic writeToFile:filename atomically:YES];
    
}

//读取存放在一级分类信息
+ (NSMutableArray *)readOneCategoryData {
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    
    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"OneCateGoryData.plist"];
    //读文件
    NSMutableArray *dic = [NSMutableArray arrayWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return dic;
}
//存储一级分类数据
+(void)SaveOneCategoryDataDataToLocationWithArr:(NSMutableArray *)OneCategoryArr{
    //1. 创建一个plist文件
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    //NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"OneCateGoryData.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    
    //NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    //创建一个dic，写到plist文件里
    //    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];
    //    [dic writeToFile:filename atomically:YES];
    
    [OneCategoryArr writeToFile:filename atomically:YES];
}

//读取存放在本地的搜索车型数据信息
+ (NSMutableArray *)readSearchCarData{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    
    NSLog(@"---%@", path);
    //获取一个plist文件
    NSString *filename=[path stringByAppendingPathComponent:@"saveCarData.plist"];
    //读文件
    NSMutableArray *dic = [NSMutableArray arrayWithContentsOfFile:filename];//[NSMutableArray arrayWithContentsOfFile:filename];
    return dic;
}
//存储搜索车型数据信息
+(void)SaveSearchCarToLocationWithDic:(NSMutableArray *)searchCarArr{
    
    //1. 创建一个plist文件
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"saveCarData.plist"];
    //创建
    NSFileManager* fm = [NSFileManager defaultManager];
    [fm createFileAtPath:filename contents:nil attributes:nil];
    
    //NSDictionary* dic = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    //创建一个dic，写到plist文件里
    //    NSDictionary* dic = [NSDictionary dictionaryWithObjectsAndKeys:@"sina",@"1",@"163",@"2",nil];
    //    [dic writeToFile:filename atomically:YES];
    
    [searchCarArr writeToFile:filename atomically:YES];

}
//清除搜索车型数据信息
+ (void)cleanSearchCarData{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths objectAtIndex:0];
    NSLog(@"path = %@",path);
    NSString *filename=[path stringByAppendingPathComponent:@"saveCarData.plist"];
    NSMutableArray *dic = [[NSMutableArray alloc] initWithCapacity:0];
    [dic writeToFile:filename atomically:YES];
}

@end
